<script setup>
import { onBeforeMount,reactive,ref, toRefs } from 'vue';
import { getPVDetailHandler as getDetail } from '../../api/pv';
import { useRoute } from 'vue-router';
import { useItem } from '../../store';
import CreateOrEdit from './CreateOrEdit.vue';
const route = useRoute()
const useItemer = useItem()
let showEdit = ref(false)
const data = reactive({
  item:{}
})
// 1. 获取当前编辑的资源配置
onBeforeMount(async ()=>{
  // 获取请求参数
  //例如http://example.com/deployment/edit?clusterId=123&namespace=default 
  // clusterId=123&namespace=default
  const requestQuery =  route.query
  await getDetail(requestQuery).then((res)=>{
    console.log("获取资源配置:",res.data.data.item)
    // 2. 把当前数据赋值给pinia
    data.item = JSON.parse(JSON.stringify(res.data.data.item))
    showEdit.value = true
  })
})
const {item} = toRefs(data)
</script>

<template>
  <CreateOrEdit v-if="showEdit" :method="route.query.method" :item="item"></CreateOrEdit>
</template>

<style scoped>

</style>
